package com.example.upload.controller;

import com.example.upload.dto.ExecShellParamDTO;
import com.example.upload.service.UploadFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;



/**
 * 文件上传处理器
 * @author admin
 */
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private UploadFileService uploadFileService;

    /**
     * 上传文件
     * @param file
     * @return
     */
    @PostMapping("/file")
    public String uploadFile(@RequestParam MultipartFile file) {
        //前端没有选择文件，srcFile为空
        if (file.isEmpty()) {
            return "文件不存在";
        }
        return uploadFileService.saveFile(file);
    }

    /**
     * 执行脚本
     * @param paramDTO
     * @return
     */
    @PostMapping("/execShell")
    public String execShell(@RequestBody ExecShellParamDTO paramDTO){
        return uploadFileService.execShell(paramDTO);
    }

}
